// packageE/location/location.js
const app = getApp();
var location = require("../../../mybehaviors/location/location");
// var app = getApp();
Component({
  behaviors: [location],
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
    page_id: {
      type: null
    }
  },
  data: {
    address: "",
    point: {
      lat: '',
      lng: ''
    },
    city: "",
    web_view_url: "",
    photobzhaoxiang: "",
    saoyisao: "",
    line:"",
    bgcimg:"",
    bgccolor:""
  }, // 私有数据，可用于模板渲染

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {

    },
    moved() { },
    detached() { },
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {

  },
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
    this._getLocation((mapdata, e) => {
      this.setData({
        address: mapdata.address,
        city: mapdata.address_component.city ? mapdata.address_component.city : mapdata.address_component.province,
        point: e
      });
    });
    let { photograph_color, scan_color,preview_color } = this.data.datas;
    this.setData({
      photobzhaoxiang: photograph_color.isColor ? photograph_color.color : '#e8e8e8',
      saoyisao: scan_color.isColor ? scan_color.color : '#e8e8e8',
      line: preview_color.isColor ? preview_color.color : '#e8e8e8',
      bgcimg:preview_color.isColor == 2? preview_color.image: '',
      bgccolor:preview_color.color || '#f8f8f8'
    })
  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() { },
    hide() { },
    resize() { },
  },

  methods: {
    tolocation() {
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      const url = `/${currentPage.route}?page_id=${this.data.page_id}`;
      wx.setStorageSync('diyurl', url);
      wx.navigateTo({
        url: '/packageC/o2o/o2oLocation/o2oLocation?tag=diy'
      });

    },
    camera() { },
    scanCode() {
      // 只允许从相机扫码
      wx.scanCode({
        onlyFromCamera: true,
        success: (res) => {
          this.setData({
            web_view_url: res.result
          })
        }
      })
    },
    // 上传图片
    multipleMethod(event) {
      const { file } = event.detail;
      let that = this;
      let urlStr = app.getNetAddresss("upload.uploadPic");
      // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
      wx.uploadFile({
        url: urlStr,
        filePath: file.url,
        name: 'file',
        success(resdata) {
          let {result,msg,data} = JSON.parse(resdata.data);
          if(result) {
            console.log(data.img_url);
            wx.navigateTo({
              url: '/packageI/scanpictureGoods/scanpictureGoods?url='+data.img_url,
            })
          };
          const { fileList = [] } = that.data;
          // fileList.push({ ...file, url: res.data.img_url, status: "done", message: '上传完成' });
          // that.setData({ fileList });
        },
        fail(err) {
          let fileList = [];
          // fileList.push({ ...file, url: '', status: "failed", message: '上传失败' });
          // that.setData({ fileList });
        }
      });
    },
    tosearch() {
      // if (!this.data.city) {
      //   wx.showToast({
      //     icon: 'none',
      //     title: '请先选择城市',
      //     duration: 1000
      //   });
      //   return;
      // }
      // let search_type = this.data.datas.search_type || 'store';
      // wx.navigateTo({
      //   url: '/packageC/o2o/o2oSearchMultiple/o2oSearchMultiple?city=' + this.data.city + '&point=' + JSON.stringify(this.data.point) + '&search_type=' + search_type
      // });
      //#95630 取消跳转门店搜索页 跳转到普通商品搜索
      wx.navigateTo({
        url: '/packageB/member/category/search_v2/search_v2',
      })
    },
  }
});
